import SceneUi from "../scene/SceneUi";
import ResMgr from "../../common/res/ResMgr";
import GameSpeakerUi from "./GameSpeakerUi";
import GamePlayerUi from "./GamePlayerUi";
import Net from "../../common/net/Net";
const {ccclass, property} = cc._decorator;

@ccclass
export default class GameUi extends cc.Component {
    @property(cc.Node)
    bgNode:cc.Node=null;
    gameSpeakerUi:GameSpeakerUi = null;
    @property(cc.Node)
    playersNode:Array<cc.Node> = [];
    start () {
        var scale = Math.max(cc.winSize.width/this.bgNode.width, cc.winSize.height/this.bgNode.height)
        this.bgNode.setScale(scale);
        // ResMgr.insPrefab("ui/game/GameSpeakerUi", (node)=>{
        //     node.parent = this.node;
        //     this.gameSpeakerUi = node.getComponent(GameSpeakerUi);
        //     this.gameSpeakerUi.setSpeaker(0, new Date().getTime() + 30*1000);
        // });
        for (let index = 0; index < 4; index++) {
            ResMgr.insPrefab("ui/game/GamePlayerUi", (node)=>{
                node.parent = this.playersNode[index];
                node.getComponent(GamePlayerUi).setPlayerIndex(index);
            });
        }
    };
    closeButtonClick(){
        SceneUi.enterMain();
        Net.request("connector.entryHandler.exitRoom", {}, (err, data)=>{
            if (!err) {
                console.log("退出房间成功");
            }
        });
    };
}
